//
//  LiuEmoticonView.swift
//  LiuWeiBo
//
//  Created by 刘晓晨 on 2017/4/6.
//  Copyright © 2017年 刘晓晨. All rights reserved.
//

import UIKit

class LiuEmoticonView: UIView {

    //懒加载控件
    fileprivate lazy var emoticonView:LiuEmoticonCollectionView = LiuEmoticonCollectionView()
    
    fileprivate lazy var emoticonToolbar:LiuEmoticonToolBarView = LiuEmoticonToolBarView()
    
    //懒加载pagecontrol
    fileprivate lazy var pageControl:UIPageControl = {
        let pagecontrol = UIPageControl()
        //        pagecontrol.pageIndicatorTintColor = UIColor(patternImage: UIImage(named: "compose_keyboard_dot_normal")!)
        //        pagecontrol.currentPageIndicatorTintColor = UIColor(patternImage: UIImage(named: "compose_keyboard_dot_selected")!)
        pagecontrol.numberOfPages = 6
        pagecontrol.currentPage = 1
        pagecontrol.hidesForSinglePage = true
        pagecontrol.setValue(UIImage(named: "compose_keyboard_dot_selected"), forKey: "currentPageImage")
        pagecontrol.setValue(UIImage(named: "compose_keyboard_dot_normal"), forKey: "pageImage")
        //_currentPageImage
        //_pageImage
        //        //运行时查看属性
        //        var outcount:UInt32 = 0
        //        if let array = class_copyIvarList(UIPageControl.self, &outcount) {
        //            for i in 0..<outcount {
        //                let list = array[Int(i)]
        //                print(String(cString: ivar_getName(list)))
        //            }
        //        }
        
        
        return pagecontrol
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    fileprivate func setupUI() {
        
        addSubview(emoticonView)
        addSubview(emoticonToolbar)
        
        
        
        emoticonView.snp.makeConstraints { (make) in
            make.left.top.right.equalToSuperview()
            make.bottom.equalTo(emoticonToolbar.snp.top)
        }
        
        emoticonToolbar.snp.makeConstraints { (make) in
            make.left.bottom.right.equalToSuperview()
            make.height.equalTo(35)
        }
        
        //添加pagecontrol
        addSubview(pageControl)
        
        //自动布局
        pageControl.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.bottom.equalTo(emoticonView)
            make.height.equalTo(10)
        }
        
        emoticonToolbar.buttonActionClosure = {[weak self] (type)->() in
            if let weakSelf = self {
                weakSelf.emoticonView.changeOffset(type: type)
            }
        }
        
        emoticonView.scrollClosure = {[weak self] (section)->() in
            if let weakSelf = self {
                weakSelf.emoticonToolbar.changeButtonType(section: section)
            }
        }
        
        emoticonView.scrollPageClosure = {[weak self] (indexPath)->() in
            if let weakSelf = self {
                weakSelf.pageControl.numberOfPages = LiuEmoticonTool.sharedEmoticonManager.emoticonArray[indexPath.section].count
                weakSelf.pageControl.currentPage = indexPath.item
            }
        }
  
    }

}




